<template>
	<view class="text_main">
		<view class="text_titles">问题的种类</view>
		<view class="text_tips">
			<text class="text">体验建议</text>
			<text class="text">商品问题</text>
			<text class="text">其他</text>
		</view>
		<view>问题描述</view>
		<view class="text_content">
			<textarea :value="textVal" @input="handleTextInput" placeholder="请输入您的描述,以便于我们更好的服务。"
				class="text_tool"> </textarea>

		</view>
		<!-- <view class="action">图片上传</view>
		<view class="text_button">
			<button @tap="handleChooseImg">+</button>
		</view> -->

		<view class="cu-bar bg-white margin-top">
			<view class="action">
				图片上传(选填)
			</view>
			<view class="action">
				{{imgList.length}}/4
			</view>
		</view>
		<view class="cu-form-group">
			<view class="grid col-4 grid-square flex-sub">
				<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage"
					:data-url="imgList[index]">
					<image :src="imgList[index]" mode="aspectFill"></image>
					<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
						<text class='cuIcon-close'></text>
					</view>
				</view>
				<view class="solids" @tap="ChooseImage" v-if="imgList.length<4">
					<text class='cuIcon-cameraadd'></text>
				</view>
			</view>
		</view>

		<!-- <view class="img" v-for="(item, index) in chooseImgs" v-key="*this" @tap="handleRemoveImg" :key="index">
			<upImg :src="item"></upImg>
		</view> -->

		<view class="text_problem">
			<view>联系方式(选填)</view>
			<textarea class="text_contact" placeholder="请输入您的联系方式">  </textarea>
		</view>

		<view class="form_button">
			<button type="primary" @tap="handleSubmit">提交反馈</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				textVal: "",
				uploadImgs: [],
				imgList: [],
				modalName: null,
				index: -1,
			}
		},
		methods: {
			//文本域输入事件
			handleTextInput() {
				textVal: e.detail.value;
			},
			//图片事件
			ChooseImage() {
				uni.chooseImage({
					//类型
					mediaType: 'image',
					//数量
					count: 4,
					//是否压缩
					sizeType: ['original', "compressed"],
					//来源
					sourceType: ['album', 'camera'],
					success: (res) => {
						if (this.imgList.length != 0) {
							this.imgList = this.imgList.concat(res.tempFilePaths)
						} else {
							this.imgList = res.tempFilePaths
						}
					}
				})
			},
			//预览图片
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			//删除图片
			DelImg(e) {
				uni.showModal({
					title: '删除照片',
					content: '确定要删除这张照片吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			}

		}
	}
</script>

<style>
	@import url("../../colorui_icon.css");
	@import url("../../colorui_main.css");

	.text_main {
		padding: 20rpx;
		background-color: #eeeeee;
	}

	.text_tips {
		display: flex;
		flex-wrap: wrap;

	}

	.text {
		width: 30%;
		padding: 10rpx;
		text-align: center;
		background-color: #fff;
		margin: 20rpx 10rpx;
	}

	.text_content {
		background-color: #fff;
		margin-top: 20rpx;
	}

	.text_tool {
		height: 400rpx;
		padding: 10rpx
	}

	.text_button {
		display: flex;
		flex-wrap: wrap;
		font-size: 60rpx;
		width: 120rpx;
		height: 100rpx;
		padding: 10rpx;
		justify-content: center;
		align-items: center;
		margin-top: 50rpx;
		color: #ccc;
		margin-left: 1rpx;


	}

	.text_contact {
		margin-top: 10rpx;
		background-color: #fff;
		height: 100rpx;
		width: 100%;
	}

	.form_button {
		display: flex;
		margin-top: 120rpx;
	}

	.text_problem {
		margin-top: 80rpx;

	}

	.img {
		margin-top: 20rpx;
		display: flex;
		margin: 20rpx;
		flex-direction: row;
		margin-left: 20rpx;

	}
</style>
